/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package cn.ekuma.epos.datalogic.define.dao;

import cn.ekuma.data.dao.I_ParentNode;
import cn.ekuma.data.dao.ModifiedLogDAO;

import com.openbravo.bean.Service;
import com.openbravo.bean.ServiceDayState;
import com.openbravo.data.basic.BasicException;
import com.openbravo.data.loader.DataRead;
import com.openbravo.data.loader.DataWrite;
import com.openbravo.data.loader.Datas;
import com.openbravo.data.loader.I_Session;
import com.openbravo.data.loader.PreparedSentence;
import com.openbravo.data.loader.SerializerWriteString;
import com.openbravo.data.loader.Session;
import com.openbravo.data.loader.TableDefinition;
import com.openbravo.data.model.Field;
import com.openbravo.format.Formats;
import java.util.List;

/**
 *
 * @author Administrator
 */
public class ServiceDayStateDAO extends ModifiedLogDAO<ServiceDayState>{

    public ServiceDayStateDAO(I_Session s) {
        super(s);
    }

    @Override
    public TableDefinition getTable() {
        return new TableDefinition(s,
                "SERVICEDAYSTATE",
                new Field[]{
                          new Field("ID",Datas.STRING,Formats.STRING),
                          new Field("SERVICE_ID",Datas.STRING,Formats.STRING),
                          new Field("ABLE",Datas.BOOLEAN,Formats.BOOLEAN),
                          new Field("STARTDATE",Datas.TIMESTAMP, Formats.TIMESTAMP),
                          new Field("ENDDATE",Datas.TIMESTAMP, Formats.TIMESTAMP),
                          new Field("MEMO",Datas.STRING,Formats.STRING),
                          new Field("LASTMODIFIED",Datas.TIMESTAMP, Formats.TIMESTAMP)
                },
                new int[]{0});
    }

    @Override
    public void writeInsertValues(DataWrite dp, ServiceDayState obj) throws BasicException {
        dp.setString(1,obj.getId());
        dp.setString(2,obj.getServiceId());
        dp.setBoolean(3,obj.isAble());
        dp.setTimestamp(4,obj.getStart());
        dp.setTimestamp(5,obj.getEnd());
        dp.setString(6,obj.getMemo());
        dp.setTimestamp(7, obj.getLastModified());
    }


    @Override
    public Class getSuportClass() {
        return ServiceDayState.class;
    }

    public ServiceDayState readValues(DataRead dr,ServiceDayState obj) throws BasicException {
        if(obj==null)
        	obj=new ServiceDayState();
        obj.setId(dr.getString(1));
        obj.setServiceId(dr.getString(2));
        obj.setAble(dr.getBoolean(3));
        obj.setStart(dr.getTimestamp(4));
        obj.setEnd(dr.getTimestamp(5));
        obj.setMemo(dr.getString(6));
        obj.setLastModified(dr.getTimestamp(7));
        return obj;
    }

    @Override
    public List list(I_ParentNode parent) throws BasicException {
        if(parent.getParentClass().equals(Service.class))
             return  new PreparedSentence(s, getTableDefinition().getListSQL()+" WHERE SERVICE_ID = ?", SerializerWriteString.INSTANCE, this).list(parent.getParentKey().getKey());
        return super.list(parent);
    }



}
